#ifndef HASHJOINBOX_H_JM_20120910
#define HASHJOINBOX_H_JM_20120910
/** @file HashJoinBox.h
* _OK_ Obsahuje HashJoinBox vykonavajuci logiku 2 kroku hashjoinu parovanie 
* nad zaheshovanou tabulkou. 
**/
// ##
#include "HashActivityBufferedOutputBox.h"
#include "HashActivityHandlerImpls.h"

#include <jmlib/logger/Logger.h>
namespace jm4bbx {
	/** 
	* HashJoinBox vykonava logiku 2 kroku hashjoinu parovanie nad zaheshovanou 
	* tabulkou. 
	* 
	* HashJoinBox v metode {@link handleRecord(valueType, ExtendedHashEntry) 
	* postupne vykonava join zaznamov, ktore maju rovnaky hash. 
	* 
	* Tato trieda obstarava logiku pre obe varianty joinu tj. klasicky 
	* mnozinovy join a aj pre multiset join.
	* 
	**/
	template<class HashBoxType>
	class HashJoinBox : 
		public HashActivityBufferedOutputBox<HashBoxType, HashJoinHandler<HashBoxType>> {
			JM_USE_LOGGER(HJoinB)

	public:
		HashJoinBox(const BoxParamPack& p) 
			: HashActivityBufferedOutputBox(p)	{ }
	protected:

		/// Synchronizacia nie je nutna pretoze sa z tabulky len cita.
		virtual bool synchronize() const  override { return false; };

		///**	 
		//* Najdenie odpovedajucich hodnot podla hashu vykona rodic a tato 
		//* metoda je zavolana na sparovane zaznamy a ma obsatarat len 
		//* logiku db operacie. 
		//* 
		//* V pripade joinu je situacia trivialna a na 
		//* vystup je poslanych tolko vysledkov kolko je poloziek s rovnakym 
		//* hashom v tabulke.
		//*  */
		//virtual void handleRecord(transferValueType value, 
		//	typename HTH::ExtendedHashEntry& entry) 
		//	override {

		//		assert(entry.getCount() == 1);

		//		auto end = entry.plainEntry.value.end();
		//		for (auto it = entry.plainEntry.value.begin(); it != end; ++it) {				
		//			BinaryOperationResultIndex index = {*it, value.getIndex()};

		//			addOutputData(index);
		//		}	
		//} 

		//virtual void handleNoRecord(transferValueType value) override { }
	};

	/// Hash join pre zaznamy s klucom typu int.
	typedef HashJoinBox<IntegerHashBox> IntegerHashJoinBox;

	/// Hash join pre zaznamy s klucom typu std::string.
	typedef HashJoinBox<StringHashBox> StringHashJoinBox;
} // namespace jm4bbx


#endif
